package com.ysh.smartplatform.utils;

import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

/**
 * 袁胜虎 on 2022/9/5 11:36
 */
public class MyStringUtils {
    public static  String salt = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";

    public static String  createRandomString(int lenght){
        List<String> list = salt.chars().mapToObj(shuzi->(char)shuzi+"").collect(Collectors.toList());
        //是可以存储和操作字符串，即包含多个字符的字符串数据
        StringBuffer stringBuffer = new StringBuffer();
        //打乱集合
        Collections.shuffle(list);
        //创建一个随机的对象
        Random random = new Random();
        for (int i = 0; i <lenght; i++) {
            //随机得到一个数字
            int randonNum = random.nextInt(356554545);
            //从指定的下标获取数据
            stringBuffer.append(list.get(randonNum % list.size()));
        }
        return stringBuffer.toString();
    }
}
